// 角色接口管理
import request from "@/utils/request";
import type {
  RoleType,
  RolePageResponse,
  RolesResponse,
  RoleResponse,
  RoleEditResponse,
  RolePageRequest,
  RoleAllocMenuRequest,
  RoleLoadMenuResponse,
} from "./types";

enum API {
  ROLE_PAGE = "role/page",
  ROLE_LIST = "role/list",
  ROLE_CREATE_OR_EDIT = "role/createOrEdit",
  ROLE_GET_BY_ID = "role/getById",
  ROLE_REMOVE = "role/remove",
  ROLE_ALLOC_MENU = "role/allocMenu",
  ROLE_LOAD_MENU = "role/loadMenu",
}

export const roleList = () => request.get<any, RolesResponse>(API.ROLE_LIST);

export const rolePage = (data: RolePageRequest) =>
  request.post<any, RolePageResponse>(API.ROLE_PAGE, data);

export const roleCreateOrEdit = (data: RoleType) =>
  request.post<any, RoleEditResponse>(API.ROLE_CREATE_OR_EDIT, data);

export const roleGetById = (id: number) =>
  request.get<any, RoleResponse>(API.ROLE_GET_BY_ID + `/${id}`);

export const roleRemove = (id: number) =>
  request.delete<any, RoleEditResponse>(API.ROLE_REMOVE + `/${id}`);

export const roleAllocMenu = (data: RoleAllocMenuRequest) =>
  request.post<any, RoleEditResponse>(API.ROLE_ALLOC_MENU, data);

export const roleLoadMenu = (id: number) =>
  request.get<any, RoleLoadMenuResponse>(API.ROLE_LOAD_MENU + `/${id}`);
